
<!doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <link rel="icon" href="../dist/img/favicon-32x32.png" sizes="32x32" type="image/png">
  <link rel="icon" href="../dist/img/favicon-16x16.png" sizes="16x16" type="image/png">
  <meta name="keywords" content="响应式后台模板,开源免费后台模板,Bootstrap5后台管理系统模板">
  <meta name="description" content="bootstrap-admin基于bootstrap5的免费开源的响应式后台管理模板">
  <meta name="author" content="ajiho">
  <link rel="stylesheet" href="../lib/bootstrap-icons/font/bootstrap-icons.min.css">
  <link rel="stylesheet" href="../lib/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="../lib/bootstrap-table/dist/bootstrap-table.min.css">
  <link rel="stylesheet"
        href="../lib/bootstrap-table/dist/extensions/fixed-columns/bootstrap-table-fixed-columns.min.css">
  <link rel="stylesheet" href="../lib/@eonasdan/tempus-dominus/dist/css/tempus-dominus.min.css"/>
  <link rel="stylesheet" href="../lib/bootstrap-select/dist/css/bootstrap-select.min.css">
  <link rel="stylesheet" href="../dist/css/bootstrap-admin.min.css">
  <title>bootstrap-admin开源免费响应式后台管理系统模板</title>
</head>
<body class="bg-body-tertiary py-3">

<div class="container-fluid">
  <div class="card border-0 shadow-sm">
    <div class="card-header bg-body py-3">
      <form class="row row-cols-sm-auto g-3 align-items-center"  action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
        <div class="col-12">
          <div class="row">
            <label for="username" class="col-sm-auto col-form-label">用户名</label>
            <div class="col">
              <input type="text" class="form-control" id="username" name="username">
            </div>
          </div>
        </div>
        <div class="col-12">
          <div class="row">
            <label for="phone" class="col-sm-auto col-form-label">手机号</label>
            <div class="col">
              <input type="text" class="form-control" id="phone" name="phone">
            </div>
          </div>
        </div>
        <div class="col-12">
          <div class="row">
            <label for="beginTime" class="col-sm-auto col-form-label">创建时间</label>
            <div class="col">
              <div class="input-group">
                <input type="text" readonly class="form-control" aria-label="q"
                       placeholder="开始时间"
                       name="beginTime" id="beginTime">
                <span class="input-group-text"><i class="bi bi-arrow-left-right"></i></span>
                <input type="text" readonly class="form-control" aria-label="q"
                       placeholder="结束时间"
                       name="endTime" id="endTime">
              </div>
            </div>
          </div>
        </div>
        <div class="col-12">
          <div class="row">
            <label for="status" class="col-sm-auto col-form-label">用户状态</label>
            <div class="col">
              <select class="selectpicker">
                <option value="0">所有</option>
                <option value="1">正常</option>
                <option value="2">停用</option>
              </select>
            </div>
          </div>
        </div>


        <div class="col-12 gap-2">

          <button type="submit" class="btn btn-light bsa-querySearch-btn">
            <i class="bi bi-search"></i>搜索
          </button>
          <!-- <button type="submit" class="btn btn-light bsa-reset-btn">
            <i class="bi bi-arrow-clockwise"></i>重置
          </button> -->

        </div>

      </form>
    </div>
    <?php
$link=mysqli_connect('127.0.0.1','root','root','books-system');
mysqli_set_charset($link, 'utf8');
//获取所有用户信息
$username = isset($_POST['username']) ? $_POST['username'] : '';
$phone = isset($_POST['phone']) ? $_POST['phone'] : '';
$all="select * from user  LEFT JOIN role ON user.roleid=role.roleid  ";
if (!$username) {
  $run = $run ;
}elseif(!$phone){
  $run = $run ;
};
if ($username) {
  $run = $run." where username like '%$username%' or name like '%$username%'"  ;
  if ($phone) {
    $run = $run . " and phone like '%$phone%'" ;
    
  }
}else{
  if ($phone) {
    $run =$run. " where phone like '%$phone%'"  ;
    
  }
};
$query1="select count(*) from user";
$result1= mysqli_query($link,$query1);
 $count= mysqli_fetch_row($result1);
 $count=$count[0];
 $page=isset($_GET['page'])?$_GET['page']:1;
$pagesize=5;
$maxpage=ceil($count/$pagesize);
$start=($page-1)*$pagesize;
$run = $run ." limit $start,$pagesize";
$all = "select * from user  LEFT JOIN role ON user.roleid=role.roleid  " . $run;
$result=mysqli_query($link, $all);
$data=mysqli_fetch_all($result,MYSQLI_ASSOC);
// print_r($all);
?>
    <div class="card-body">
      <!--  表格上方左侧的工具条区域    -->
      <!-- <div id="toolbar" class="d-flex flex-wrap gap-2 mb-2">
        <a href="user-add.php"><button class="btn btn-light add-btn"><i
          class="bi bi-plus"></i> 新增
        </button></a>
        
        <button class="btn btn-light batch-btn" disabled><i class="bi bi-trash"></i> 批量删除</button>
        <button class="btn btn-light"><i class="bi bi-box-arrow-down"></i> 导入</button>
        <button class="btn btn-light"><i class="bi bi-box-arrow-up"></i> 导出</button>
      </div> -->

      
      <div id="toolbar" class="d-flex flex-wrap gap-2 mb-2">
        <button class="btn btn-light add-btn"><i
          class="bi bi-plus"></i> 新增
        </button>
        <button class="btn btn-light batch-btn" disabled><i class="bi bi-trash"></i> 批量删除</button>
        <button class="btn btn-light"><i class="bi bi-box-arrow-down"></i> 导入</button>
        <button class="btn btn-light"><i class="bi bi-box-arrow-up"></i> 导出</button>
      </div>
      <nav aria-label="Page navigation example">
  <ul class="pagination justify-content-end">
    <li class="page-item ">
      <a class="page-link" href="user.php?page=1">首页</a>
    </li>
    <li class="page-item"><a class="page-link" href="user.php?page= <?php  echo $page-1 > 0?($page-1):1 ?>">上一页</a></li>
    <li class="page-item"><a class="page-link" href="#">当前页：<?php echo $page ?></a></li>
    <li class="page-item"><a class="page-link" href="user.php?page=<?php echo $page+1 < $maxpage? ($page+1):$maxpage ?>">下一页</a></li>
    <li class="page-item">
      <a class="page-link" href="user.php?page=<?php echo $maxpage?>">尾页</a>
    </li>
  </ul>
</nav>
      <!--  数据表格    -->
      <table id="table" class="table table-bordered">
      <thead>
      <tr>
        <th>用户编号</th>
        <th>用户名称</th>
        <th>姓名</th>
        <th>邮箱</th>
        <th>性别</th>
        <th>密码</th>
        <th>权限</th>
        <th>加入日期</th>
        <th>状态</th>
        
        
        <th>操作</th>
      </tr>
      
    </thead>
    
    <tbody>
    <?php
//显示所有用户信息
foreach ($data as $v){
   echo "<tr>"; 
   echo '<td>';    echo $v['id'];                  echo '</td>';
   echo '<td>';    echo $v['username'];            echo '</td>';
   echo '<td>';    echo $v['name'];                echo '</td>';
   echo '<td>';    echo $v['emali'];            echo '</td>';
   echo '<td>';    
   if ($v['sex']==2){
    echo "女" ;
   }elseif ($v['sex']==1) {
    echo "男" ;
   }else echo "保密" ;          
   echo '</td>';
   echo '<td>';    echo $v['password'];              echo '</td>';
   echo '<td>';    echo $v['role'];                  echo '</td>';
   echo '<td>';    echo $v['creat_at'];                  echo '</td>';
   echo '<td>';    
   if ($v['status']==0){
    echo "正常" ;
   }else echo "停用"; 
   ;                  
   echo '</td>';
   echo '<td>';    echo '<a href=user-edit.php?username='.$v['username'].'><i class="bi bi-pencil">编辑</i></a>';  echo '<a href=user-edit.php?username='.$v['username'].'><i class="bi bi-trash3">删除</i></a>';           echo '</td>';
  //  echo '<td>';    echo $v['info'];                echo '</td>';
   echo "</tr>";
}
?>
</tbody>
      </table>
    </div>
  </div>
</div>
<!--回到顶部开始-->
<a href="javaScript:" class="bsa-back-to-top"><i class='bi bi-arrow-up-short'></i></a>
<!--回到顶部结束-->

<script src="../lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="../lib/jquery/dist/jquery.min.js"></script>
<script src="../lib/@popperjs/core/dist/umd/popper.min.js"></script>
<script src="../lib/@eonasdan/tempus-dominus/dist/js/tempus-dominus.min.js"></script>
<script src="../lib/bootstrap-table/dist/bootstrap-table.min.js"></script>
<script src="../lib/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="../lib/bootstrap-table/dist/extensions/fixed-columns/bootstrap-table-fixed-columns.min.js"></script>
<script src="../lib/bootstrap-select/dist/js/bootstrap-select.min.js"></script>
<script src="../lib/bootstrap-select/dist/js/i18n/defaults-zh_CN.min.js"></script>
<script src="../dist/js/bootstrap-admin.min.js"></script>
<script src="../dist/js/app.js"></script>
<!--假数据模拟,生产环境中请直接删除该js-->
<!-- <script src="../dist/js/bootstrap-admin.mock.js"></script> -->

<script>
$(document).ready(function (e) {
// 新增用户
$('.add-btn').on('click', function () {
      // window :建议加上该前缀,否则在子页面中通过parent.modalInstance 获取不到该实例对象,因为它现在处于一个匿名函数里
      window.modalInstance = $.modal({
        url: 'user-add.html',
        title: '用户添加',
        //禁用掉底部的按钮区域
        buttons: [],
        modalDialogClass: 'modal-dialog-centered modal-lg',
        onHidden: function (obj, data) {
          if (data === true) {
            //刷新当前数据表格
            $('#table').bootstrapTable('refresh');
            $('#table').bootstrapTable('selectPage', 1)//跳转到第一页
          }
        }
      })
    })

});

</script>

</body>
</html>
